const Router = require('@koa/router');
const { Spell } = require('../db/schemas')

const { Language } = require('../env');
const { genResponse, raw$project } = require('../utils');

const router = new Router({ prefix: '/spell' })

router.get('/', async (ctx) => {
  const results = await Spell.aggregate([
    {
      $project: {
        _id: 0,
        id: 1,
        name: `$name.${Language}`,
        description: `$description.${Language}`,
        updated_at: 1,
        raw: '$$ROOT'
      }
    },
    raw$project,
  ])
  ctx.body = genResponse(true, results)
})
// router.post('/', async (ctx) => {
// })
// router.put('/:id', async (ctx) => {
// })
// router.delete('/:id', async (ctx) => {
// })
module.exports = router